﻿using UnityEngine;
using System.Collections;

public class Parallax : MonoBehaviour 
{
    public float parallaxMin, parallaxMax;

    Transform mainCameraPos;
    Vector3 firstCameraPos;
    Vector3 firstPos;

    float parallax;

    void Start()
    {
        parallax = Random.RandomRange(parallaxMin, parallaxMax);
        mainCameraPos = GameObject.FindGameObjectWithTag("MainCamera").transform;
        firstCameraPos = new Vector3(mainCameraPos.position.x, mainCameraPos.position.y, mainCameraPos.position.z);
        firstPos = new Vector3(transform.position.x, transform.position.y, transform.position.z);
    }

    void Update()
    {
        Vector3 dif = mainCameraPos.position - firstCameraPos;
        transform.position = firstPos + dif / parallax;
    }
}
